﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Module;
using System.Web.UI.HtmlControls;
using BLL.Common;
using Enum;

namespace App
{
    public partial class FamousRegion_FamousRegion : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            pageInit();
        }

        protected void rptRegionDynamic_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                PaperInfo p = e.Item.DataItem as PaperInfo;
                HtmlAnchor link = e.Item.FindControl("lb_RegionDynamic") as HtmlAnchor;

                if (p != null && p.PaperId > 0 && link != null)
                {
                    link.InnerText = p.Subject;
                    link.HRef = Contexts.AppPath + "/FamousRegion/FamousDynamicPaper.aspx?" + Contexts.PaperId + "=" + Contexts.GetEncrypt(p.PaperId.ToString());
                }

            }
            if (e.Item.ItemType == ListItemType.Footer)
            {
                if (rptRegionDynamic.Items.Count <= 0)
                {
                    ((Label)e.Item.FindControl("lblNoRecord")).Visible = true;
                }
            }
        }
        protected void rptRegionNarrative_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                PaperInfo p = e.Item.DataItem as PaperInfo;
                HtmlAnchor link = e.Item.FindControl("lb_RegionNarrative") as HtmlAnchor;

                if (p != null && p.PaperId > 0 && link != null)
                {
                    link.InnerText = p.Subject;
                    link.HRef = Contexts.AppPath + "/FamousRegion/FamousNarrativePaper.aspx?" + Contexts.PaperId + "=" + Contexts.GetEncrypt(p.PaperId.ToString());
                }

            }
            if (e.Item.ItemType == ListItemType.Footer)
            {
                if (rptRegionDynamic.Items.Count <= 0)
                {
                    ((Label)e.Item.FindControl("lblNoRecord")).Visible = true;
                }
            }
        }
        private void pageInit()
        {
            //获取全月专区信息
            List<FamousRegionInfo> regions = BLL.BFamousRegion.getInstance().GetAllFamousRegions();
            if (regions == null || regions.Count == 0)
                return;
            FamousRegionInfo regionInfo = regions[0];
            List<RegionCategoryInfo> categorys = BLL.BRegionCategory.getInstance().GetAllRegionCategoryByFamousRegionId(regionInfo.FamousRegionId);
            //fUserImg.Src=
            fUserImg.Src = BLL.Common.UploadResource.GetPath(BLL.Common.BizResourceType.UserResource, BLL.Common.BizResourceAccess.Display) + regionInfo.ImageSrc;
            List<PaperInfo> Pages = new List<PaperInfo>();
            foreach (RegionCategoryInfo o in categorys)
            {
                if (o.CategoryType == (int)CategoryType.PersonalDynamic)
                {
                    Pages = BLL.BPaper.getInstance().GetAllRegionCategoryTop10(o.RegionCategoryId);
                    if (Pages != null)
                    {
                        this.rptRegionDynamic.DataSource = Pages;
                        this.rptRegionDynamic.DataBind();
                        this.linkD.HRef = BLL.Common.Contexts.AppPath + "/FamousRegion/FamousDynamicPaperList.aspx?" + Contexts.RegionCategoryId + "=" + Contexts.GetEncrypt(o.RegionCategoryId.ToString());
                    }
                }
                else if (o.CategoryType == (int)CategoryType.PersonalNarrative)
                {
                    Pages = BLL.BPaper.getInstance().GetAllRegionCategoryTop10(o.RegionCategoryId);
                    if (Pages != null)
                    {
                        this.rptRegionNarrative.DataSource = Pages;
                        this.rptRegionNarrative.DataBind();
                        this.linkN.HRef = BLL.Common.Contexts.AppPath + "/FamousRegion/FamousNarrativePaperList.aspx?" + Contexts.RegionCategoryId + "=" + Contexts.GetEncrypt(o.RegionCategoryId.ToString());
                    }
                }
                else if (o.CategoryType == (int)CategoryType.PersonalResume)
                {
                    Pages = BLL.BPaper.getInstance().GetAllRegionCategoryTop10(o.RegionCategoryId);
                    if (Pages != null)
                    {
                        PaperInfo p = Pages[0];
                        this.div_resume.InnerHtml = p.Body;
                        this.linkPerson.HRef = BLL.Common.Contexts.AppPath + "/FamousRegion/FamousPerson.aspx?" + Contexts.PaperId + "=" + Contexts.GetEncrypt(p.PaperId.ToString());
                    }

                }

            }
        }
    }
}